package com.movieproject.src;


import java.util.Map;

import com.movieproject.daos.MovieDAO;
import com.movieproject.daos.UserDAO;
import com.movieproject.dataobjects.Movie;
import com.movieproject.dataobjects.User;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping(value = "/newMovie")
public class AddMovieController {

	@RequestMapping(method = RequestMethod.GET)

	public String viewRegistration(Map<String, Object> model) {
		Movie movieForm = new Movie(); 
		model.put("movieForm", movieForm);


		return "AddMovie";
	}

	@RequestMapping(method = RequestMethod.POST)
	public String processRegistration(@ModelAttribute("movieForm") Movie movie,
			Map<String, Object> model) {

		ApplicationContext context = new ClassPathXmlApplicationContext("Spring-Module.xml");

		MovieDAO movieDAO = (MovieDAO) context.getBean("movieDAO");
		
		String title = movie.getTitle();
		String actors = movie.getActors();
		String genre = movie.getGenre();
		String rating = movie.getRating();
		String desc = movie.getDescription();
		String year = movie.getYear();
		String img = movie.getImageURL();


		Movie movies = new Movie(title,actors,desc,genre,img,rating,year);
		movieDAO.insert(movies);

		return "AddMovieSuccess";
	}

}
